#!/bin/sh

# Set up a compute node.

#
# exit if LSF_ENVDIR is not set
#
if [ -z "$LSF_ENVDIR" ]; then
    echo "LSF_ENVDIR is not set. Exiting..."
    exit 1
fi

# source the lsf.conf file
if [ ! -f "$LSF_ENVDIR/lsf.conf" ]; then
    echo "$LSF_ENVDIR/lsf.conf not found. Exiting..."
    exit 1
fi

. $LSF_ENVDIR/lsf.conf

# install the volclava startup file
cp --backup=numbered $LSF_ENVDIR/volclava /etc/init.d

ln -sf $LSF_ENVDIR/volclava.sh /etc/profile.d/volclava.sh
ln -sf $LSF_ENVDIR/volclava.csh /etc/profile.d/volclava.csh 

# configure the lava service to start at boot
osType=$(sed -n '/^NAME=/ {s/^NAME="//;s/"$//;p}' /etc/os-release)

if [ "$osType" = "Ubuntu" ]; then
    /lib/systemd/systemd-sysv-install enable volclava
else
    /sbin/chkconfig --add volclava
    /sbin/chkconfig volclava on
fi
